from coin.exchange.base.kr_rest.product import NativeProduct, NormProduct
from coin.exchange.huobi.config import group_symbol
from coin.exchange.ftx.kr_rest.currency import FTXCurrency
from coin.exchange.ftx.kr_rest.constants import (
    symbol_list,
    quote_currency_list,
    base_currency_list,
)


class FTXProduct(NativeProduct):
  _exchange = "Ftx"
  NativeCurrencyType = FTXCurrency

  def __init__(self, base, quote):
    native_symbol = "%s/%s" % (base.native_symbol, quote.native_symbol)
    NativeProduct.__init__(self, base, quote, native_symbol)

  @classmethod
  def FromStrProductImpl(cls, product, current_datetime):
    assert type(product) == str
    assert "-" in product
    ret = product.split("-")
    assert len(ret) == 2
    base = FTXCurrency.FromStrCurrency(ret[0])
    quote = FTXCurrency.FromStrCurrency(ret[1])
    return FTXProduct(base, quote)

  @classmethod
  def FromStrNativeProductImpl(cls, product, current_datetime):
    assert isinstance(product, str), type(product)
    assert product in symbol_list, product
    base, quote = product.split('/')
    assert base in base_currency_list, base
    base = FTXCurrency.FromStrNativeCurrency(base, current_datetime)
    assert quote in quote_currency_list, quote
    quote = FTXCurrency.FromStrNativeCurrency(quote, current_datetime)
    return FTXProduct(base, quote)
